/*!
 * Ext JS Library 3.4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.chart.Chart.CHART_URL = '/ad/html/publish/js/charts.swf';
var store=null;
Ext.onReady(function(){
	var dobFieldEditor = {
			xtype:'datefield',
			allowBlank:false, 
			blankText:'此欄不可空白',
			editable:false,
			format:'20y-m-d',
			value:new Date(), 
			listeners: {  
		        'change' : 
		        	function( field, newValue, oldValue) {
		        		store.reload(
		        			{
		        				
		        				params:{"dateEnd" : field.getValue().format('Y-m-d')}
		        			}
		        		);
		            }  
		                  
		        }
		};
       store = new Ext.data.JsonStore({
    	 proxy: new Ext.data.HttpProxy({  
            method: 'GET',  
            url:"/ad/sys/com/control/publish/ClickedAdService.php?action=queryReport&chartsAccount="+getUser().Account
//            ,extraParams: {"dateEnd" : new Date().format('Y-m-d')}  
        }),
		root : "row", 
		remoteSort: false,
		totalProperty: 'count',
		fields : ["Date", "Sum"]
    });
    store.load(
    		{params:{"dateEnd" : new Date().format('Y-m-d')}}
    		);
    // extra simple
    new Ext.Panel({
        iconCls:'chart',
        title: '收益',
        frame:false,
        renderTo: 'container',
        width:524,
        height:230,
        layout:'fit',
        tbar:{
        	xtype:'toolbar',
        	items:[
        		// searchTB,
        		'->',
        		// { xtype:'button', iconCls:this.btnIcons.add, text:'新增',
				// handler:this.addRec, scope:this, scale:'medium' },
        		dobFieldEditor,
        		]
        	},
        items: {
            xtype: 'linechart',
            store: store,
            url: Ext.chart.Chart.CHART_URL,
            xField: 'Date',
            yField: 'Sum',
            yAxis: new Ext.chart.NumericAxis({
                displayName: 'Sum',
                labelRenderer : Ext.util.Format.numberRenderer('0,0')
            }),
            tipRenderer : function(chart, record){
                return Ext.util.Format.number(record.data.Sum, '0,0') + ' visits in ' + record.data.Date;
            }
        }
    });

});